package com.zhou.ab;

import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.AbstractLoadBalancerRule;
import com.netflix.loadbalancer.Server;

import java.util.List;

public class ABRibbonRule extends AbstractLoadBalancerRule{



    @Override
    public void initWithNiwsConfig(IClientConfig iClientConfig) {
        System.out.println("执行了初始化的方法：initWithNiwsConfig");
    }

    @Override
    public Server choose(Object key) {
        List<Server> serverList = this.getLoadBalancer().getAllServers();
        for (Server server : serverList){
            System.out.println("服务列表："+ server.getHost()+server.getHostPort());
        }
        int index = (int)(Math.random() * 2);
        System.out.println("选择服务："+ index);
        return serverList.get(0);
    }
}
